package com.chongbangbang.controller.pet;


import com.alibaba.fastjson.JSON;
import com.chongbangbang.pojo.PetInfo;
import com.chongbangbang.service.PetInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 宠物基本信息 前端控制器
 * </p>
 *
 * @author TP
 * @since 2022-03-16 15:20:37
 */
@RestController
@RequestMapping("/chong/pet/pet")
@Api(tags = "pet info", value = "宠物基本信息")
public class PetInfoController {
    @Autowired
    private PetInfoService petInfoService;

    /**
     *  查询所有
     * @return
     */
    @ApiOperation("查询所有")
    @RequestMapping(value = "", method = RequestMethod.GET)
    public List<PetInfo> get(){
        return petInfoService.list();
    }

    /**
     * 根据宠物ID查询
     * @return
     */
    @ApiOperation("根据宠物ID查询")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public PetInfo getByPetId(@PathVariable Integer id){
        return petInfoService.getById(id);
    }

    /**
     * 根据用户ID查询
     * @return
     */
    @ApiOperation("根据用户ID查询")
    @RequestMapping(value = "/user/{userId}", method = RequestMethod.GET)
    public List<PetInfo> getByUserId(@PathVariable Integer userId){
        return petInfoService.getByUserId(userId);
    }

    /**
     * 单个插入
     */
    @ApiOperation("单个插入")
    @RequestMapping(value = "", method = RequestMethod.POST)
    public boolean post(PetInfo petInfo) {
        return petInfoService.save(petInfo);
    }


    /**
     * 批量插入
     */
    @ApiOperation("批量插入")
    @RequestMapping(value = "/_mcreate", method = RequestMethod.POST)
    public boolean postBatches(@ApiParam(value = "传ArrayList<PetInfo>") ArrayList<PetInfo> list){
        return petInfoService.saveBatch(list);
    }

    /**
     * 根据ID更新
     */
    @ApiOperation("根据ID更新")
    @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
    public boolean putById(@ApiParam(name = "id", value = "id要单独传") @PathVariable("id")Integer id, PetInfo petInfo) {

        return petInfoService.updateById(petInfo);
    }

    @ApiOperation("批量更新")
    @RequestMapping(value = "/_mupdate", method = RequestMethod.PUT)
    public boolean putBatches(@ApiParam(value = "传ArrayList<PetInfo>") ArrayList<PetInfo> list) {
        return petInfoService.updateBatchById(list);
    }

    @ApiOperation("根据ID删除")
    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    public boolean deleteById(@PathVariable Integer id) {
        return petInfoService.removeById(id);
    }

    @ApiOperation("根据ID批量删除")
    @RequestMapping(value = "/_mdelete", method = RequestMethod.DELETE)
    public boolean deleteById(@ApiParam(value= "传ArrayList<Integer>") ArrayList<Integer> list) {
        return petInfoService.removeById(list);
    }

}
